<%
'#-------------------------------------------------------------------------------#
'#  Description:       KIR and Diseases spreadsheet by e-mail.                   #
'#                     Code:      dis2001a_mail.asp                              #
'#  Author:            Louise Yukari Cicalise Takeshita                          #
'#  Created:           26 Jun 2012.                                              #
'#  Ended:             26 Jun 2012.                                              #
'#  Last update:       26 Jun 2012.                                              #
'#  Version:           1.0.0 - 26-Jun-2012                                       #
'#  Bugs:                                                                        #
'#-------------------------------------------------------------------------------#
%>
<%
		'//... Retrieving Variables ...//
		dis_id = Request.QueryString("dis_id")
		dis_corr_auth = Request.QueryString("dis_corr_auth")	
		dis_email = Request.QueryString("dis_email")
		dis_name = Request.QueryString("dis_name")						

		'//... Create spreadsheet ...//'
		Dim sSpreadsheet
		sPath = Server.MapPath(".") & "\pops\"
		
		sSpreadsheet = "<table border='1' style='font='Verdana, Arial, Helvetica, sans-serif''>"
		sSpreadsheet = sSpreadsheet & "<tr><td colspan='4' rowspan='2' valign='top'><font color='green'><b>KIR and Disease Association Data Input Sheet</b></font></td>"
		sSpreadsheet = sSpreadsheet	& "<td colspan='5'><b>DO NOT AMEND ANYTHING ON THIS SPREADSHEET. ONLY ADD REQUIRED DATA SPECIFIED IN &ldquo;INSTRUCTIONS.PDF&rdquo; FILE.</td></tr>"
		sSpreadsheet = sSpreadsheet	& "<tr><td><b>Before proceeding, please save this spreadsheet.</b></td></tr>"
		sSpreadsheet = sSpreadsheet & "<tr><td colspan='9'><b>Study ID: </b>" & dis_id & "</td></tr>"
		sSpreadsheet = sSpreadsheet & "<tr><td colspan='9'><b>Disease: </b>" & dis_name & "</td></tr>"
		sSpreadsheet = sSpreadsheet & "<tr><td colspan='9'><b>Corresponding Author: </b>" & dis_corr_auth & "</td></tr>"
		sSpreadsheet = sSpreadsheet & "<tr><td colspan='9'><b>Date and Time: </b>" & now & "</td></tr>"
		sSpreadsheet = sSpreadsheet & "<tr><td colspan='15'></td></tr>"
		sSpreadsheet = sSpreadsheet & "<tr><td colspan='9' valign='top' border='0'><b>NEGATIVE ASSOCIATIONS</b></td>"
		sSpreadsheet = sSpreadsheet & "<td colspan='6' valign='top'><b>RAW GENOTYPIC DATA</b></td></tr>"
		sSpreadsheet = sSpreadsheet & "<tr><td><b>KIR GENE</b></td><td><b>Association Type</b></td><td><b>Controls</b></td><td><b>Special Controls</b></td><td><b>Patients</b></td>"
		sSpreadsheet = sSpreadsheet & "<td><b>Odds Ratio</b></td><td><b>P-value</b></td><td><b>Statistic Method</b></td><td><b>Correction</b></td>"
		sSpreadsheet = sSpreadsheet & "<td colspan='2'><b>Controls</b></td><td colspan='2'><b>Special Controls</b></td><td colspan='2'><b>Patients</b></td></tr>"
		sSpreadsheet = sSpreadsheet & "<tr><td><b></b></td><td><b>Freq</b></td><td><b>Freq</b></td><td><b>Freq</b></td>"
		sSpreadsheet = sSpreadsheet & "<td></td><td></td><td></td><td></td><td></td></tr>"
		sSpreadsheet = sSpreadsheet & "<td><b>Genotype</b></td><td><b>ID</b></td><td><b>Genotype</b></td><td><b>ID</b></td><td><b>Genotype</b></td><td><b>ID</b></td>"
		sSpreadsheet = sSpreadsheet & "<tr><td><b></b></td><td><b>(%)</b></td><td><b>(%)</b></td><td><b>(%)</b></td>"
		sSpreadsheet = sSpreadsheet & "<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>"
		sSpreadsheet = sSpreadsheet & "<tr><td colspan='15'></td></tr>"
		sSpreadsheet = sSpreadsheet & "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>"
		sSpreadsheet = sSpreadsheet & "<tr><td colspan='9' valign='top' border='0'><b>POSITIVE ASSOCIATIONS</b></td>"
		sSpreadsheet = sSpreadsheet & "<td></td><td></td><td></td><td></td><td></td><td></td></tr>"
		sSpreadsheet = sSpreadsheet & "</table>"
		
		Dim fs, f 
		set fs=Server.CreateObject("Scripting.FileSystemObject") 			
		set f=fs.CreateTextFile(sPath + Trim("DISKIR" & dis_id) + ".xls", true)
		
					
		f.WriteLine(sSpreadsheet)
		f.Close
		
		Set f=nothing
		Set fs=nothing
		Set sSpreadsheet=nothing

		'//... E-mail Body ...//'		
		strEmailSubject = "New population - " & dis_id & " - Instructions for submitters"
		
		strEmailBody =  "Dear Colleague " + chr(13) + chr(13)
		strEmailBody = strEmailBody + "This is an automatic notification. In this e-mail you will find enclosed two files "
		strEmailBody = strEmailBody + "(input spreadsheet and instructions). Please proceed to fill the spreadsheet and when "
		strEmailBody = strEmailBody + "completed send back this information to the address provided in the instructions file."
		strEmailBody = strEmailBody + " If you have any query, do not hesitate to contact us." + chr(13) + chr(13)
		strEmailBody = strEmailBody + "Thanks for your contribution," + chr(13) + chr(13)
		strEmailBody = strEmailBody + "Best regards" + chr(13) + chr(13) + chr(13) 
		strEmailBody = strEmailBody + "The Allele Frequency Net Database" + chr(13)
		strEmailBody = strEmailBody + "http://www.allelefrequencies.net" + chr(13)			
%>
<%		

 		
		'//... Create e-mail ...//'
		Set Mail = Server.CreateObject("Persits.MailSender")
		   	
		Mail.Host ="smtp-relay.allelefrequencies.net"
		Mail.From = "postmaster@allelefrequencies.net"
		Mail.FromName = "The Allele Frequency Net Database" 
		Mail.AddAddress dis_email
		Mail.Subject = strEmailSubject		
		Mail.Body = strEmailBody
		Mail.AddAttachment  sPath + Trim("DISKIR" & dis_id) + ".xls"
		Mail.AddAttachment  sPath + "instructions.pdf"	
		
		On Error Resume Next
		Mail.Send
		If Err <> 0 Then
			Response.Write "Error encountered: " & Err.Description
		End If
		
		Response.Write("OK!")
		
%>		
	
